package Test;

import hypertension.*;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * This is a sample file to launch a process.
 */
public class Flowtest {

    public static final void main(String[] args) {
        try {
            // load up the knowledge base
            KnowledgeBase kbase = readKnowledgeBase();
            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
            KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
            // start a new process instance
            
            
           Symptoms s1= new Symptoms();
           //s1.addToSymptoms("newly HTN");
           //s1.addToSymptoms("fall");
           s1.addToSymptoms("IHD");
           
           System.out.println("Symptoms: "+s1);
           
           
           Historys h1=new Historys();
           //h1.addToHistorys("IHD");
           //h1.addToHistorys("HF");
           //h1.addToHistorys("Home ambulatory monitoring");
           System.out.println("Case Historys: "+h1);
          
          
          
           Medicines m1=new Medicines();
           //m1.isChange();
           System.out.println("medicine change?: " + m1.change);
           
           Indicator I1=new Indicator("systolic BP",145);
           Indicator I2=new Indicator("systolic BP",160);
           Indicator I3=new Indicator("diastolic BP",180);
           Indicator I4=new Indicator("new systolic BP",130);
           
           
           ksession.insert(s1);
           ksession.insert(h1);
           ksession.insert(m1);
           ksession.insert(I1);
           ksession.insert(I2);
           ksession.insert(I3);
           ksession.insert(I4);
           /* ksession.insert(h1);
            ksession.insert(m1);*/
          
            
            ksession.startProcess("hypertension.Flow");
            logger.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    private static KnowledgeBase readKnowledgeBase() throws Exception {
    	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(ResourceFactory.newClassPathResource("Flow.rf"), ResourceType.DRF);
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if (errors.size() > 0) {
            for (KnowledgeBuilderError error: errors) {
                System.err.println(error);
            }
            throw new IllegalArgumentException("Could not parse knowledge.");
        }
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        return kbase;
    }

}
